﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using log4net;
using Common;

namespace CashFlow.ShopManage.Filters
{
    public class CustomErrorFilterAttribute : HandleErrorAttribute
    {
        private static ILog _logger = LogManager.GetLogger(typeof(CustomErrorFilterAttribute));

        public override void OnException(ExceptionContext filterContext)
        {
            string str = MyWebTool.GetHttpRequestInfo(filterContext.HttpContext);
            string str2 = string.Format("CustomErrorFilterAttribute.OnException, Msg: {0}{1}",
                filterContext.Exception.Message,
                str);
            _logger.Fatal(str2, filterContext.Exception);

            if (!filterContext.ExceptionHandled)
            {
#if RELEASE
                filterContext.HttpContext.Response.StatusCode = 500;
                filterContext.ExceptionHandled = true;
                filterContext.HttpContext.Server.ClearError();
                filterContext.Result = new ContentResult
                {
                    Content = "Error"
                };
#endif
            }
        }
    }
}